#delimit;
pause on;
clear all;
set mem 50m;
pause;
set more off;
pause;
cd "C:\data\Veto points\JOP_December08\Replication";
pause;
use "veto0208_replication.dta", clear;
pause;
save "veto0208_replication_v1.dta", replace;
pause;
log using "Replication_Setup.smcl", replace;



/*Prepare and Label Cross-Sectional Variables*/

by country_, sort: egen polcon_average=mean(polcon3);
lab var polcon_average "Average Political Constraints (1992-2004)";

by country_, sort: egen polity_average=mean(p_polity);
lab var polity_average "Average Democracy (1992-2004)";

by country_, sort: egen eu_average=mean(eu);
lab var eu_average "Average Relationship with EU (1992-2004)";
by country_, sort: egen war_average=mean(war);
replace war_average=war_average*100;
lab var war_average "Percentage of Time in War (1992-2004)";

replace p_parcomp=. if p_parcomp<0;
by country_, sort: egen alpha_average=mean(p_parcomp);

lab var alpha_average "Alpha (Concern for Social Welfare)";
pause;

drop gdp_cap;
generate ln_gdpcap=ln((gdp*1000000)/population);

by country_, sort: egen lngdpcap_average= mean(ln_gdpcap);
lab var lngdpcap_average "Average GDP per Capita (1992-2004)";




/*Correct Postcommunist Coding to make compatible with Darden and Busse*/
replace postcoms=(100-non_comm)/100 if year<1995 & country_ == 2;
replace postcoms=(100-non_comm)/100 if year<1995 & country_ == 3;
replace postcoms=(100-non_comm)/100 if year<1995 & country_ == 4;
replace postcoms=(100-non_comm)/100 if year<1995 & country_ == 10;
replace postcoms=.2583 if year<1994 & country_ == 9;
replace postcoms=(100-non_comm)/100 if year<2000 & country_ == 13;
replace postcoms=(100-non_comm)/100 if year<1994 & country_ == 12;
replace postcoms=(100-non_comm)/100 if year<1993 & country_ == 14;
replace postcoms=(100-non_comm)/100 if year<1994 & country_ == 16;
replace postcoms=(100-non_comm)/100 if year<1993 & country_ == 19;
replace postcoms= .0950 if year==1994 & country_ == 19;
replace postcoms=(100-non_comm)/100 if year<1995 & country_ == 22;
replace postcoms=(100-non_comm)/100 if year<1999 & country_ == 23;
replace postcoms=(100-non_comm)/100 if year<1994 & country_ == 24;
replace postcoms=(100-non_comm)/100 if year<1995 & country_ == 25;
replace postcoms=(100-non_comm)/100 if country_ == 26;
replace postcoms=(100-non_comm)/100 if year==1992 & country_ == 27;

by country_, sort: egen postcom_average=mean(postcomseats);
lab var postcom_average "Average postcomseats in Legislature (1992-2004)";




/*View Cross-Sectional Variables*/

describe polcon_average postcom_average polity_average eu_average war_average lngdpcap_average   literacy_precomm literacy_precomm_euk nat_curriculum seats_1stelect urban_comm dem_precomm ece;
pause;


/*Create Measure of Early Reforms and Initial Polcon - 5 Year Cut-Off*/
xtset country_ year;

generate early_EBRD =l9.EBRD if year==2004 & FSU==0;
replace early_EBRD=l6.EBRD if year==2004 & FSU==1;

/*Former Yugloslavia*/
replace early_EBRD=l6.EBRD if year==2004 & country_==9;
replace early_EBRD=l4.EBRD if year==2004 & country_>25;
replace eu=2 if country_ ==27 & year>=2001;
replace eu=0 if country_ ==27 & year<2001;
replace eu=1 if country_ ==26 & year>=2001;
replace eu=0 if country_ ==26 & year<2001;

generate initial_polcon =l12.polcon3 if year==2004 & FSU==0;
replace initial_polcon=l9.polcon3 if year==2004 & FSU==1;
replace initial_polcon=l9.polcon3 if year==2004  & country_==9;
replace initial_polcon=l4.polcon3 if year==2004  & country_>25;

/*Early Relationship with EU*/
generate initial_eu =l12.eu if year==2004 & FSU==0;
replace initial_eu =l9.eu if year==2004 & FSU==1;
replace initial_eu =l9.eu if year==2004  & country_==9;
replace initial_eu =l4.eu if year==2004  & country_>25;

by country_, sort: egen war_early=mean(wartorn) if year<1994 & FSU==0;
by country_, sort: egen war_early_FSU=mean(wartorn) if year<1997 & FSU==1;
generate war_early_combined =l11.war_early;
replace war_early_combined = l8.war_early_FSU if FSU==1;
replace war_early_combined= l8.war_early if country_==9;
pause;


/*SPECIFIC RE-CODES*/

/*Parties in Hungary*/
replace parties=3 if country_ ==11;
replace partiesyugo=3 if country_ ==11;
pause;

/*Macedonia's Energy Consumption*/

replace gdp_en=5.03 if country_ == 9;
pause;


/*Updating of Checks Dataset 2008*/


replace checks=1 if  country_== 19 & year==1992;
replace checks =1 if  country_== 22 & year==1995;

/*IMPUTE OTHER MISSING CHECKS VALUES -- USING POLCON AND FRYE MEASURE'S of Vetopoints*/
xtset country_ year;
impute checks polcon3 vetopt l.checks if country_ <=26, generate(checks_new);
generate lag_EBRD=l.EBRD;
generate interchecks_new=checks_new*lag_EBRD;

/*Create Average Checks Measure*/
by country_, sort: egen checks_average=mean(checks_new);
lab var checks_average "Average Checks (1992-2004)";


drop if country_==.;

/*Re-Scale Literacy to be Consistent with Others*/
replace literacy_precomm=literacy_precomm/100;




save "veto0208_replication_v1.dta", replace;
log close;










